﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using AllInOne.ViewModels;
using PropertyChanged;

namespace AllInOne.MainPages
{
    ////弹出框传递数据
    //public delegate void DlgDialog(string value);

    /// <summary>
    /// PlateInputWindow.xaml 的交互逻辑
    /// </summary>
    [AddINotifyPropertyChangedInterface]
    public partial class PlateInputWin : Window
    {
        public event DlgDialog DlgDialogEvent_InputPlate;

        private readonly string[] _plateChar = {
            "京","津","沪","渝","冀","晋","蒙","辽","吉","黑",
            "苏","浙","皖","闽","赣","鲁","豫","鄂","湘","粤",
            "桂","琼","川","贵","云","藏","陕","甘","青","宁",
            "新","厂", "A","B","C","D","E","F","G","H",
            "J","K","L","M","N","P","Q","R","S","T",
            "U","V","W","X","Y","Z","0","1","2","3",
            "4","5","6","7", "8","9"
        };

        public PlateInputWin(string plate)
        {
            InitializeComponent();
            Plate = plate;
            ////要挂载上
            //PlateInputWinViewModel viewModel = new PlateInputWinViewModel();
            //viewModel.PlateInputWinModel = new Classes.PlateInputWinModel() { Plate = "新车牌" };
            //this.DataContext = viewModel;

            foreach (var s in _plateChar)
            {
                var btn = new Button
                {
                    Width = 100,
                    Height = 90,
                    Margin= new Thickness(0,0,0,0),
                    Content = s,
                    Background = Brushes.Transparent,
                    FontSize = 60
                };
                btn.BorderThickness=new Thickness(0);
                Border border = new Border();
                border.Width = 100;
                border.Height = 90;
                border.BorderBrush = Brushes.Red;
                border.BorderThickness = new Thickness(0);
                border.Background = Brushes.White;
                border.CornerRadius = new CornerRadius(10);
                border.Margin = new Thickness(0,15,0,0);
                border.Child = btn;
                btn.FontFamily = new System.Windows.Media.FontFamily(new Uri("pack://application:,,,/Font/SourceHanSansCN-Bold.otf"), "./#思源黑体 CN Bold");//SourceHanSansCN-Bold#思源黑体 CN Regular
                btn.Click += new RoutedEventHandler(Button_Click);
                //将btn添加到Grid中
                uniformGrid.Children.Add(border);
            }
        }

        #region 界面绑定属性

        public string Plate { get; set; } = string.Empty;

        #endregion
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (sender is Button tb)
            {
                Plate += tb.Content.ToString();
            }
                
        }

        private void Button_Click_Backspace(object sender, RoutedEventArgs e)
        {
            if (Plate.Length > 0)
                Plate = Plate.Remove(Plate.Length - 1, 1);
        }

        private void Button_Click_Clear(object sender, RoutedEventArgs e)
        {
            Plate = string.Empty;
        }

        private void Button_Click_Confirm(object sender, RoutedEventArgs e)
        {
            Close();
            if (DlgDialogEvent_InputPlate != null)
            {
                DlgDialogEvent_InputPlate(Plate);
            }
        }

        private void Button_Click_Cancel(object sender, RoutedEventArgs e)
        {
            Close();
        }

    }
}
